local skill = fk.CreateSkill{
  name = "tea__yintu",
  tags = { Skill.Compulsory }
}
local U = require "packages/utility/utility"
---@type TrigSkelSpec<UseCardFunc>
local yintu = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      local room = player.room
      local events = {}
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      if not turn_event then return end
      room.logic:getEventsByRule(GameEvent.UseCard, 999, function (e)
        local use = e.data
        if use.from == player then
          table.insert(events, use)
        end
        return false
      end, turn_event.id)
      if #events == 1 then
        event:setCostData(self, events[1])
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local members = data.tos
    if #members > 0 then
      room:setPlayerMark(player, "tea__yintu_members-turn", table.map(members, function (p)
        return p.id
      end))
    end
  end,
}
---@type TargetModSpec
local yintu_targetmod = {
  bypass_times = function(self, player, skill, scope, card, to)
    if card and to and player:hasSkill("tea__yintu", true) then
      local targetRecorded = player:getTableMark("tea__yintu_members-turn")
      return not table.contains(targetRecorded, to.id)
    end
  end,
  bypass_distances = function(self, player, skill, card, to)
    if card and to and player:hasSkill("tea__yintu", true) then
      local targetRecorded = player:getTableMark("tea__yintu_members-turn")
      return not table.contains(targetRecorded, to.id)
    end
  end,
}
skill:addEffect(fk.CardUseFinished, yintu)
skill:addEffect("targetmod", yintu_targetmod)
return skill